/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JanelaCadastrarLei.java
 *
 * Created on 03/03/2011, 13:52:09
 */
package gui;

import java.util.List;
import javax.swing.Action;
import javax.swing.JOptionPane;
import modelo.Lei;

/**
 *
 * @author emersonmx, Jaedson
 */
public class JanelaCadastrarLei extends javax.swing.JDialog implements UI {

    /** Creates new form JanelaCadastrarLei */
    public JanelaCadastrarLei(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        setLocationRelativeTo(null);
        setTitle("Cadastrar Lei");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    rotuloNumeroLei = new javax.swing.JLabel();
    rotuloProcesso = new javax.swing.JLabel();
    rotuloEmenta = new javax.swing.JLabel();
    campoNumeroLei = new javax.swing.JTextField();
    rolagemEmenta = new javax.swing.JScrollPane();
    campoEmenta = new javax.swing.JTextArea();
    rotuloTexto = new javax.swing.JLabel();
    botaoOK = new javax.swing.JButton();
    botaoCancelar = new javax.swing.JButton();
    campoProcesso = new javax.swing.JTextField();
    barraTexto = new javax.swing.JScrollPane();
    campoTexto = new javax.swing.JTextPane();
    barraFerramentas = new component.MXTextToolbar();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setTitle("Janela Cadastrar Lei");
    setMinimumSize(new java.awt.Dimension(400, 300));

    rotuloNumeroLei.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    rotuloNumeroLei.setText("Nº Lei:");

    rotuloProcesso.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    rotuloProcesso.setText("Processo:");

    rotuloEmenta.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    rotuloEmenta.setText("Ementa:");

    campoEmenta.setColumns(20);
    campoEmenta.setRows(5);
    rolagemEmenta.setViewportView(campoEmenta);

    rotuloTexto.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
    rotuloTexto.setText("Texto:");

    botaoOK.setText("Cadastrar");
    botaoOK.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        botaoOKActionPerformed(evt);
      }
    });

    botaoCancelar.setText("Cancelar");
    botaoCancelar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        botaoCancelarActionPerformed(evt);
      }
    });

    campoTexto.setContentType("text/html");
    barraTexto.setViewportView(campoTexto);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(rotuloEmenta)
              .addComponent(rotuloProcesso)
              .addComponent(rotuloNumeroLei)
              .addComponent(rotuloTexto))
            .addGap(10, 10, 10)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(campoNumeroLei, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 946, Short.MAX_VALUE)
              .addComponent(campoProcesso, javax.swing.GroupLayout.DEFAULT_SIZE, 946, Short.MAX_VALUE)
              .addComponent(rolagemEmenta, javax.swing.GroupLayout.DEFAULT_SIZE, 946, Short.MAX_VALUE)
              .addComponent(barraTexto, javax.swing.GroupLayout.DEFAULT_SIZE, 946, Short.MAX_VALUE)
              .addComponent(barraFerramentas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addComponent(botaoOK)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(botaoCancelar)))
        .addContainerGap())
    );

    layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {botaoCancelar, botaoOK});

    layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {rotuloEmenta, rotuloNumeroLei, rotuloProcesso, rotuloTexto});

    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(rotuloNumeroLei)
          .addComponent(campoNumeroLei))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(rotuloProcesso)
          .addComponent(campoProcesso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(rotuloEmenta)
          .addComponent(rolagemEmenta, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(rotuloTexto)
          .addComponent(barraFerramentas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(barraTexto, javax.swing.GroupLayout.DEFAULT_SIZE, 373, Short.MAX_VALUE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
          .addComponent(botaoCancelar)
          .addComponent(botaoOK))
        .addContainerGap())
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

  private void botaoOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoOKActionPerformed
      Lei lei = new Lei();
      lei.setNumeroLei(campoNumeroLei.getText());
      lei.setProcesso(campoProcesso.getText());
      lei.setEmenta(campoEmenta.getText());
      lei.setTexto(campoTexto.getText());
      lei.setNumeroLeiRevoga(null);
      lei.setRevogada(0);
      if (controlador.numeroLeiUnica(lei.getNumeroLei())) {
          controlador.inserir(lei);
          campoEmenta.setText(null);
          campoNumeroLei.setText(null);
          campoProcesso.setText(null);
          campoTexto.setText(null);
      } else {
          JOptionPane.showMessageDialog(this, "Lei com o mesmo número já cadastrada", "Atenção!", JOptionPane.ERROR_MESSAGE);
      }
  }//GEN-LAST:event_botaoOKActionPerformed

  private void botaoCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoCancelarActionPerformed
      setVisible(false);
  }//GEN-LAST:event_botaoCancelarActionPerformed
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private component.MXTextToolbar barraFerramentas;
  private javax.swing.JScrollPane barraTexto;
  private javax.swing.JButton botaoCancelar;
  private javax.swing.JButton botaoOK;
  private javax.swing.JTextArea campoEmenta;
  private javax.swing.JTextField campoNumeroLei;
  private javax.swing.JTextField campoProcesso;
  private javax.swing.JTextPane campoTexto;
  private javax.swing.JScrollPane rolagemEmenta;
  private javax.swing.JLabel rotuloEmenta;
  private javax.swing.JLabel rotuloNumeroLei;
  private javax.swing.JLabel rotuloProcesso;
  private javax.swing.JLabel rotuloTexto;
  // End of variables declaration//GEN-END:variables
    private Controlador controlador;
    private Lei lei;

    public Controlador getControlador() {
        return controlador;
    }

    public void setControlador(Controlador c) {
        controlador = c;
    }

    public void exibirMensagem(String mensagem) {
        JOptionPane.showMessageDialog(this, mensagem);
    }

    public void exibirMensagemErro(String mensagem) {
        JOptionPane.showMessageDialog(this, mensagem, "Erro!", JOptionPane.ERROR_MESSAGE);
    }

    public void mostrarObjeto(Object o) {
        throw new UnsupportedOperationException("Ainda não suportado!");
    }

    public void mostrarObjetos(List l) {
        throw new UnsupportedOperationException("Ainda não suportado!");
    }

    public void setNumeroLei(String toString) {
        campoNumeroLei.setText(toString);
    }

    public void setProcesso(String toString) {
        campoProcesso.setText(toString);
    }

    public void setEmenta(String toString) {
        campoEmenta.setText(toString);
    }

    public void setTexto(String toString) {
        campoTexto.setText(toString);
    }

    public void setarCampos(Lei l) {
        lei = l;
        campoEmenta.setText(lei.getEmenta());
        campoNumeroLei.setText(lei.getNumeroLei());
        campoProcesso.setText(lei.getProcesso());
        campoTexto.setText(lei.getTexto());
    }

    public void limparCampos() {
        campoEmenta.setText(null);
        campoNumeroLei.setText(null);
        campoProcesso.setText(null);
        campoTexto.setText(null);
    }
}
